<template>
  <div>
    <div
      style="font-size: 16px;font-weight: 500;color: #1D2129;margin-bottom: 16px;"
    >
      校外体育中心类型
    </div>

    <div style="display: flex; ">
      <img
        src="@/assets/img/Frame@2x.png"
        alt=""
        style="width: 32px;height: 32px; margin-right: 16px;18px;margin-top: 5px"
      />
      <div>
        <div style="font-size: 24px;color: #0F0F0F;">{{ num }}</div>
        <div style="font-size: 12px;">校外体育中心/所</div>
      </div>
    </div>

    <div
      id="Chart"
      style="width:100%;height:220px;margin-top:-20px;margin-left:-15px"
    ></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import { get_sheet6_level } from "@/api/statistics";
export default {
  name: "SchoolType",
  data() {
    return {
      chartInstance: null,
      chartdata: [],
      num: ""
    };
  },
  mounted() {
    this.datalist();
  },

  methods: {
    async datalist() {
      await get_sheet6_level().then(res => {
        this.chartdata = res.data.list;
        this.num = res.data.total;
      });

      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById("Chart"));
      // 指定图表的配置项和数据
      var option;
      option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow"
          }
        },
        legend: {},
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true
        },
        xAxis: {
          name: "所",
          type: "value",
          boundaryGap: [0, 0.01]
        },
        yAxis: {
          type: "category",
          data: ["其他", "市级", "省级", "国家级"]
        },
        series: [
          {
            type: "bar",
            data: this.chartdata,
            showBackground: true,
            backgroundStyle: {
              color: "rgba(180, 180, 180, 0.2)"
            }
          }
        ]
      };
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
      // 监听父元素大小变化 刷新图表
      var ro = new ResizeObserver(entries => {
        for (let entry of entries) {
          const cr = entry.contentRect;
          myChart.resize();
        }
      });
      ro.observe(Chart);
    }
  }
};
</script>

<style scoped>
.dianidan {
  width: 7px;
  height: 7px;
  margin-right: 5px;
  margin-top: 3px;
}
</style>
